package com.cmict.data.form.api.util.SubUtil;

import cn.hutool.core.util.ObjectUtil;
import com.cmict.data.framework.common.pojo.CommonResult;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import static com.cmict.data.framework.common.pojo.CommonResult.success;

/**
 * @description: el-input组件规则
 * @author: qiaoyu
 * @create: 2022-07-18 22:57
 **/
public class ElSliderUtil {

	public static CommonResult rule (JSONObject personData , String value , int number) {
		String message = null;
		Boolean redata = true;
		JSONArray fields = personData.getJSONArray("fields");
		JSONObject field = fields.getJSONObject(number);
		JSONObject config = field.getJSONObject("__config__");
		String label = config.getString("label");
		//是否必填
		Boolean required = config.getBoolean("required");
		if(required && ObjectUtil.isEmpty(value)){
			message = label+"是必填项;";
			redata=false;
			//return success( label+"是必填项",false);
		}
		//最大值
		int max = config.getInteger("max");
		//最小值
		int min = config.getInteger("min");
		//步长
		//int step = config.getInteger("step");
		if(Integer.parseInt(value) < max && min > Integer.parseInt(value)){
			message = label+"数据不在规则范围;";
			redata=false;
			//return success( label+"超过最大字数",false);
		}
		if(!redata){
			return success( message,false);
		}
		return success( "通过",true);
	}
}

